﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BioCompEx3
{
    //Holds the data of a line from an input file
    //and calculates the results array that holds 1 according to the different variables' values.
    class Tupple
    {
        private int empNum;
        private int empAge;
        private Boolean managerGenderMale;
        private int managerSallery;
        private String compType;
        private int isProfitable;
        private Boolean isTest;
        private int[] result;
        private const int InputNuronsCount = 39;

        /*read the values of a line into the class' variables
         * employees number, employees average age, manager gender, manager salary and company type are read for all lines
         * the profitable result of a line is read only for learning and validation lines
         * */
        public Tupple(string line, Boolean isTest)
        {
            this.isTest = isTest;
            char[] separator = new char[3];
            separator[0] = ',';
            separator[1] = ' ';
            separator[2] = '\t';
            String[] vars = line.Split(separator,StringSplitOptions.RemoveEmptyEntries);
            empNum = Convert.ToInt32(vars[0].Trim());
            empAge = Convert.ToInt32(vars[1].Trim());
            managerGenderMale = vars[2].Trim().Equals("M");
            managerSallery = Convert.ToInt32(vars[3].Trim());
            compType = vars[4].Trim();
            calcResultsArray();
            if (!isTest)
                calcIsProfirable(vars[5]);
        }

        //'+' => profitable, '-' => non-profitable
        private void calcIsProfirable(string var)
        {
            if (var.Equals("+"))
                isProfitable = 1;
            else
                isProfitable = 0;
        }

        //Getter for profitable value
        public int IsProfitable
        {      
            get
            {
                if (!isTest)
                    return isProfitable;
                else
                    return 0;
            }
        }

        //Getter for the result array
        public int[] Result { get { return result; } }

        //sets 1 in the correct place according to the different ranges, the rest remain as 0
        private void calcResultsArray()
        {
            result = new int[InputNuronsCount];
            for (int i = 0; i < InputNuronsCount; result[i] = 0, ++i) ;
            calcEmpNumResult();
            calcEmpAge();
            calcManagerGender();
            calcManagerSallery();
            calcCompType();
        }

        //a.	Range is "H"=HighTech, "L"=LowTech, "B"=BioTech
        //b.	Neurons 36-38 in the input will receive 1 according to the range in which the variable falls – 36 for "H", 37 for "L" and 38 for "B".
        private void calcCompType()
        {
            if (compType.Equals("H"))
            {
                result[36] = 1;
                return;
            }
            if (compType.Equals("L"))
            {
                result[37] = 1;
                return;
            }
            if (compType.Equals("B"))
            {
                result[38] = 1;
                return;
            }
        }

        //a.	Range is 10,000-110,000.
        //b.	Jumps for each neuron are 5,000.
        //c.	Neurons 16-35 in the input will receive 1 according to the range in which the variable falls.
        private void calcManagerSallery()
        {
            if (managerSallery >= 10000 && managerSallery <= 14999)
            {
                result[16] = 1;
                return;
            }
            if (managerSallery >= 15000 && managerSallery <= 19999)
            {
                result[17] = 1;
                return;
            }
            if (managerSallery >= 20000 && managerSallery <= 24999)
            {
                result[18] = 1;
                return;
            }
            if (managerSallery >= 25000 && managerSallery <= 29999)
            {
                result[19] = 1;
                return;
            }
            if (managerSallery >= 30000 && managerSallery <= 34999)
            {
                result[20] = 1;
                return;
            }
            if (managerSallery >= 35000 && managerSallery <= 39999)
            {
                result[21] = 1;
                return;
            }
            if (managerSallery >= 40000 && managerSallery <= 44999)
            {
                result[22] = 1;
                return;
            }
            if (managerSallery >= 45000 && managerSallery <= 49999)
            {
                result[23] = 1;
                return;
            }
            if (managerSallery >= 50000 && managerSallery <= 54999)
            {
                result[24] = 1;
                return;
            }
            if (managerSallery >= 55000 && managerSallery <= 59999)
            {
                result[25] = 1;
                return;
            }
            if (managerSallery >= 60000 && managerSallery <= 64999)
            {
                result[26] = 1;
                return;
            }
            if (managerSallery >= 65000 && managerSallery <= 69999)
            {
                result[27] = 1;
                return;
            }
            if (managerSallery >= 70000 && managerSallery <= 74999)
            {
                result[28] = 1;
                return;
            }
            if (managerSallery >= 75000 && managerSallery <= 79999)
            {
                result[29] = 1;
                return;
            }
            if (managerSallery >= 80000 && managerSallery <= 84999)
            {
                result[30] = 1;
                return;
            }
            if (managerSallery >= 85000 && managerSallery <= 89999)
            {
                result[33] = 1;
                return;
            }
            if (managerSallery >= 90000 && managerSallery <= 94999)
            {
                result[34] = 1;
                return;
            }
            if (managerSallery >= 95000 && managerSallery <= 99999)
            {
                result[35] = 1;
                return;
            }
            if (managerSallery >= 100000 && managerSallery <= 104999)
            {
                result[36] = 1;
                return;
            }
            if (managerSallery >= 105000 && managerSallery <= 110000)
            {
                result[37] = 1;
                return;
            }
        }

        //a.	Range is "M"=Male or "F"=Female.
        //b.	Neuron 15 in the input will receive 1 if the manager is a male.
        private void calcManagerGender()
        {
            if (managerGenderMale)
            {
                result[15] = 1;
            }
        }

        //a.	Range is 20-70.
        //b.	Jumps for each neuron are 10.
        //c.	Neurons 10-14 in the input will receive 1 according to the range in which the variable falls.
        private void calcEmpAge()
        {
            if (empAge >= 20 && empAge <= 29)
            {
                result[10] = 1;
                return;
            }
            if (empAge >= 30 && empAge <= 39)
            {
                result[11] = 1;
                return;
            }
            if (empAge >= 40 && empAge <= 49)
            {
                result[12] = 1;
                return;
            }
            if (empAge >= 50 && empAge <= 59)
            {
                result[13] = 1;
                return;
            }
            if (empAge >= 60 && empAge <= 70)
            {
                result[14] = 1;
                return;
            }
        }

        //a.	Range is 5-1005.
        //b.	Jumps for each neuron are 100.
        //c.	Neurons 0-9 in the input will receive 1 according to the range in which the variable falls.
        private void calcEmpNumResult()
        {
            if (empNum >= 5 && empNum <= 104)
            {
                result[0] = 1;
                return;
            }
            if (empNum >= 105 && empNum <= 204)
            {
                result[1] = 1;
                return;
            }
            if (empNum >= 205 && empNum <= 304)
            {
                result[2] = 1;
                return;
            }
            if (empNum >= 305 && empNum <= 404)
            {
                result[3] = 1;
                return;
            }
            if (empNum >= 405 && empNum <= 504)
            {
                result[4] = 1;
                return;
            }
            if (empNum >= 505 && empNum <= 604)
            {
                result[5] = 1;
                return;
            }
            if (empNum >= 605 && empNum <= 704)
            {
                result[6] = 1;
                return;
            }
            if (empNum >= 705 && empNum <= 804)
            {
                result[7] = 1;
                return;
            }
            if (empNum >= 805 && empNum <= 904)
            {
                result[8] = 1;
                return;
            }
            if (empNum >= 905 && empNum <= 1005)
            {
                result[9] = 1;
                return;
            }
        }
    }
}
